var tag = document.createElement('script');
tag.src = "//www.youtube.com/iframe_api";
var youTubeScript = document.getElementsByTagName('script')[0];
youTubeScript.parentNode.insertBefore(tag, youTubeScript);

// This function creates an <iframe> (and YouTube player) after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
	player = new YT.Player('videoDiv', {
		width: '1000',
		height: '563',
		videoId: videoId,
		events: {
			'onReady': onPlayerReady
		},
		playerVars: {
			controls: '0',
			showinfo: '0',
			rel: '0',
			iv_load_policy: '3',
			disablekb: '1'
		}
	});
}

// The API will call this function when the video player is ready.
function onPlayerReady(event) {
	//Set the interval to update the checkTime function (600 milliseconds)
	setInterval(checkTime, 600);
	checkTime();
}

function playVideo(vidID) {
	_gaq.push(["_trackEvent", "Video Play", vidID]);
	player.playVideo();
}

function pauseVideo(vidID) {
	time = String(player.getCurrentTime());
	_gaq.push(["_trackEvent", "Video Pause", vidID, time]);
	player.pauseVideo();
}

function stopVideo(vidID) {
	time = String(player.getCurrentTime());
	_gaq.push(["_trackEvent", "Video Stop", vidID, time]);
	player.seekTo(0, true);
	player.stopVideo();
}

//Full screen native browser function
function goFullscreen() {
	console.log("received fullscreen");
	// Get the element that we want to take into full screen mode
	var element = document.getElementById("videoDiv");
	// Check to see if full screen is available.
	if (Boolean(element.mozRequestFullScreen)) {
		console.log("mozilla fullscreen");
		element.mozRequestFullScreen();
	} else if (Boolean(element.webkitRequestFullScreen)) {
		console.log("webkit fullscreen");
		element.webkitRequestFullScreen(); //Chrome and Safari
	}
}
